package client.Game;

import javax.swing.JLabel;

import client.GUI.ClientGUI;

public class Timer extends Thread{
	JLabel label;
	int time = 30;
	boolean running = false;
	ClientGUI gui;

	public Timer(JLabel label, ClientGUI gui){
		this.label = label;
		this.gui = gui;
		start();
	}

	public void run(){
		while(true){
			time --;
			setLabel();
			if(time == 0){
				if(gui.WhoseTurnIsIt.getText().equals(gui.player.name + " kord on ..")){
					gui.receiver.getSender().sendAnswer("VALE");
				}
			}
			try{
				Thread.sleep(1000);
			} catch (InterruptedException e){
				e.printStackTrace();
			}

			try {
				Thread.sleep(100);
			}catch (InterruptedException e){
				e.printStackTrace();
			}
		}
	}

	public void reset() {
		time = 30;
		setLabel();	
	}

	private void setLabel() {
		String result = "";
		if(time<10){
			result = "00:0" + time;
		}else{
			result = "00:" + time;
		}
		label.setText(result);
	}

}
